<?php
/**
 * Created by PhpStorm.
 * User: wuchunyin
 * Date: 2018/11/15
 * Time: 20:31
 */

namespace app\index\table;
use think\Db;

abstract class BaseTable {

    protected static $table;
    protected static $pk;

    public static function table(){
        return Db::table(static::$table);
    }

    public static function get($data){
        if(is_string($data)){
            return static::table()->where([static::$pk=>$data])->find();
        }
        if(is_array($data)){
            return static::table()->where($data)->find();
        }
    }

    public static function toDate(&$data,$key){
        if(array_key_exists($key,$data)){
            $value = $data[$key];
            if(empty($value)){
                $data[$key] = null;
            }
            else{
                $data[$key] = Db::raw("to_date('$data[$key]','yyyy-mm-dd hh24:mi:ss')");
            }
        }
    }


}